package cn.life.business.factory.controller;

import cn.life.business.factory.entity.po.FactoryPo;
import cn.life.business.factory.service.FactoryService;
import cn.life.common.entity.model.CMessage;
import cn.life.common.entity.model.MyUser;
import cn.life.common.entity.model.MyUserInfo;
import cn.life.common.utils.RequestPoSetUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Description:    工厂Controller
 *
 * @Author 李佳明
 * @Date 2018/7/19 0019 下午 1:05
 */
@RestController
@RequestMapping("factory")
public class FactoryController {


    @Autowired
    private FactoryService factoryService;

    /**
     * @Description:    增加工厂
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("add")
    public CMessage addFactory(@RequestBody FactoryPo actoryPo, @MyUser MyUserInfo myUserInfo) throws IllegalAccessException {
        setOprData(actoryPo,myUserInfo);
        return  factoryService.addFactory(actoryPo);
    };

    /**
     * @Description:    增加工厂
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("update")
    public CMessage updateFactory(@RequestBody FactoryPo actoryPo){
        return  factoryService.updateFactory(actoryPo);
    };

    /**
     * @Description:    增加工厂
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("delete")
    public CMessage deleteFactory(@RequestBody FactoryPo actoryPo){
        return  factoryService.deleteFactory(actoryPo);
    };

    /**
     * @Description:    查询工厂详情
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("queryDetail")
    public CMessage queryFactoryDetail(@RequestBody FactoryPo actoryPo){
        return  factoryService.queryFactoryDetail(actoryPo);
    };


    public void setOprData(FactoryPo actoryPo,MyUserInfo myUserInfo){
        actoryPo.setOprUserId(myUserInfo.getUserId());
        actoryPo.setOprUserName(myUserInfo.getUserName());
        actoryPo.setOprDate(new Date());
    }
}
